#include<bits/stdc++.h>
using namespace std;
struct information{
    long long int id;
    int shijiid;
    int setid;
}a[1000];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].id;
        cin>>a[i].shijiid;
        cin>>a[i].setid;
    }
    int m;
    cin>>m;
    while(m--)
    {
        int temp;
        cin>>temp;
        for(int i=0;i<n;i++)
        {
            if(a[i].shijiid==temp){
                cout<<a[i].id<<" "<<a[i].setid<<endl;
            }
        }
    }
    return 0;
}
